<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      >
    <h:head>
        <title>Quản lí Categories</title>
        <script>
            function confirmComplete() {
                var answer = confirm("Bạn có chắc chắn muốn xóa bản ghi này?");
                if (answer == true)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        </script>        
    </h:head>
    <h:body> 
        <link type="text/css" rel="stylesheet" href="../css/main.css" />        
        <style type="text/css">
            .ui-widget{font-size:95% !important;}
            .ui-layout-unit-content{background-color: #E5E5E5;border-width: 0px}      
            .ui-widget{border-width: 0px;color: red}
        </style>
        <div align="center" id="bodyForm" >            
            <div style="width: 100%;">
                <p:layoutUnit id="top" position="north" size="auto">
                    <ui:insert name="menu">
                        <ui:include src="../../templates/menu.xhtml"/>
                    </ui:insert>
                </p:layoutUnit>

                <p:layoutUnit id="center" position="center" size="400">
                    <h:form id="form">
                        <br></br>
                        <p:dialog modal="true" widgetVar="statusDialog" header="#{bundle_contTem_vi.Searching}"   
                                  draggable="false" closable="false">  
                            <p:graphicImage value="../../images/ajax-loader.gif" />  
                        </p:dialog>
                        <p:growl id="messages"/> 
                        <h:outputText value="Name: "/><p:inputText value="#{categoryController.nameS}"/>
                        <p:commandButton value="Search" icon="ui-icon ui-icon-search" action="#{categoryController.search()}" onclick="statusDialog.show();" oncomplete="statusDialog.hide();" update=":form"/>
                        <p:commandButton value="Add" icon="ui-icon ui-icon-plusthick" onclick="dlgAdd.show()" action="#{categoryController.updateInsert()}" update=":formAdd"/>
                        <p:dataTable value="#{categoryController.items}" var="c" paginator="true" rows="20" paginatorPosition="bottom">
                            <p:column headerText="Id">
                                <h:outputText value="#{c.id}" style="float: right"/>
                            </p:column>
                            <p:column headerText="Code">
                                <h:outputText value="#{c.code}" style="float: right"/>
                            </p:column>
                            <p:column headerText="Name">
                                <h:outputText value="#{c.name}" style="float: right"/>
                            </p:column>
                            <p:column headerText="Parent Id">
                                <h:outputText value="#{c.parent_id}" style="float: right"/>
                            </p:column>
                            <p:column headerText="Edit" style="width: 2%">
                                <p:commandButton styleClass="ui-icon ui-icon-pencil" style="width: 20px;height: 20px" onclick="dlgEdit.show()" actionListener="#{categoryController.updateForEdit()}" update=":formEdit"/>
                            </p:column>
                            <p:column headerText="Delete" style="width: 2%">
                                <p:commandButton styleClass="ui-icon ui-icon-trash" style="width: 20px;height: 20px" onclick="return confirmComplete()" action="#{categoryController.remove()}"/>
                            </p:column>
                        </p:dataTable>
                    </h:form>
                    <!--dialog them-->
                    <p:dialog widgetVar="dlgAdd" modal="true" header="Add Category">
                        <h:form id="formAdd">
                            <h:panelGrid columns="2">
                                <h:outputText value="Code: "/><p:inputText value="#{categoryController.currentCate.code}"/>
                                <h:outputText value="Name: "/><p:inputText value="#{categoryController.currentCate.name}"/>
                                <h:outputText value="Parent Id: "/><p:inputText value="#{categoryController.currentCate.parent_id}"/>
                                <h:outputText value=""/><p:commandButton value="Save" action="#{categoryController.insert()}" update=":form" oncomplete="dlgAdd.hide()"/>
                            </h:panelGrid>
                        </h:form>
                    </p:dialog>
                    <!--dialog sua-->
                    <p:dialog widgetVar="dlgEdit" modal="true" header="Edit Category">
                        <h:form id="formEdit">
                            <h:panelGrid columns="2">
                                <h:outputText value="Code: "/><p:inputText value="#{categoryController.currentCate.code}"/>
                                <h:outputText value="Name: "/><p:inputText value="#{categoryController.currentCate.name}"/>
                                <h:outputText value="Parent Id: "/><p:inputText value="#{categoryController.currentCate.parent_id}"/>
                                <h:outputText value=""/><p:commandButton value="Save" action="#{categoryController.update()}" update=":form" oncomplete="dlgEdit.hide()"/>
                            </h:panelGrid>
                        </h:form>
                    </p:dialog>                    
                </p:layoutUnit>
                <p:layoutUnit id="bottom" position="bottom" size="60">
                    <ui:insert name="footer">
                        <ui:include src="../../templates/footer.xhtml"/>
                    </ui:insert>
                </p:layoutUnit>
            </div>
        </div>
    </h:body>
</html>

